<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-menu default-active='active' mode='horizontal' class='menu-unit'>
          <el-menu-item v-for='item in Container2' :index="'产品报价'===item.name?'active':'default'">
            <el-link @click="gotoMenu(item.url)" :type="'产品报价'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
        <table cellpadding="4" cellspacing="0" border="0" width="100%">
          <tr>
            <td class="containerBack">
              <el-form ref="form" :model="cmessg" :rules="rules" label-width="100px" id="mvcfm">
                <el-button @click="contactsOfferAddSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
                <el-button @click="gotoPage('/crm/sale/contacts/ContactsOffer?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
                <div class="form-unit">
                  <span class="mvc-title-left"> 添加新报价 </span>
                </div>
                <div>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="主题" prop="quo_theme">
                        <el-input v-model="cmessg.quo_theme" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="客户" prop="">
                        {{cmessg.client_name}}
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="商机" prop="quo_predict">
                        <el-select style='width:100%' v-model="cmessg.predict_theme">
                          <el-option label="－－无－－" value='' />
                          <el-option v-for="dict in s_predict" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="客户等级" prop="">
                        {{cmessg.description}}
                      </el-form-item>
                    </el-col>
                  </el-row>
                </div>
                <div class="form-unit">
                  <span class="mvc-title-left"> 列表条目 </span>
                </div>
                <el-table :data="s_top">
                  <el-table-column label="操作" prop="" width="60">
                    <template slot-scope="scope">
                      <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
                      <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
                    </template>
                  </el-table-column>
                  <el-table-column label="产品选择" prop="">
                    <template slot-scope="scope">
                      {{scope.row.pronum_prodece}}
                      <el-button @click="popProductChoce('','pronum_prodece')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                    </template>
                  </el-table-column>
                  <el-table-column label="数量" prop="">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.pronum_no" />
                    </template>
                  </el-table-column>
                  <el-table-column label="单价" prop="price_pro">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.price_pro" />
                    </template>
                  </el-table-column>
                  <el-table-column label="交货地点" prop="" width="50">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.pronum_address" />
                    </template>
                  </el-table-column>
                  <el-table-column label="交货时间" prop="">
                    <template slot-scope="scope">
                      <el-date-picker v-model="scope.row.pronum_endate" type="date" style='width:100%' value-format="yyyy-MM-dd" />
                    </template>
                  </el-table-column>
                  <el-table-column label="简要描述" prop="" width="20">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.pronum_remark" />
                    </template>
                  </el-table-column>
                </el-table>
                <div>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="备注" prop="quo_insides">
                        <el-input type="textarea" v-model="quo_price.quo_insides" ttparea=350></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </div>
                <el-button @click="contactsOfferAddSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
                <el-button @click="gotoPage('/crm/sale/contacts/ContactsOffer?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>取消</el-button>
              </el-form>
            </td>
          </tr>
        </table>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'联系人'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="ProductChoceVisible" append-to-body>
      <ProductChoce v-if="ProductChoceVisible" ref="ProductChoce" :popparams="popparams"> </ProductChoce>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import ProductChoce from "@/views/crm/sale/ProductChoce";
  export default {
    name: 'ContactsOfferAdd',
    components: {
      ProductChoce,
    },
    props: ['popparams'],
    data() {
      return {
        ProductChoceVisible: false,
        ProductChoceValue: null,
        ProductChoceDesc: null,
        vueparams: this.getVUEParams(""),
        cmessg: {
          quo_theme: null,
          client_name: null,
          predict_theme: null,
          description: null,
        },
        s_top: [],
        quo_price: {
          quo_insides: null,
        },
        s_predict: [],
        loading: false,
        Container: null,
        Container2: null,
        rules: {
          quo_theme: [{
            required: true,
            message: "主题不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
      this.loadContainerMenu({
        pid: "80299289AF2443B18EA545A4C0C37170",
        name: "客户管理右菜单",
        selected: "联系人"
      }, 'Container', this.vueparams);
      this.loadContainerMenu({
        pid: "14ED91704E794C43A973E8BEFF724C15",
        name: "客户联系人右菜单",
        selected: "产品报价"
      }, 'Container2', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/crm/sale/contacts/ContactsOffer/contactsOfferAdd?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      contactsOfferAddSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/crm/sale/contacts/ContactsOffer/contactsOfferAddSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/crm/sale/contacts/ContactsOfferDet/contactsOfferDet?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popProductChoce(desc, value) {
        this.ProductChoceVisible = true;
        this.ProductChoceDesc = desc;
        this.ProductChoceValue = value;
      },
      closeProductChoce(value, desc) {
        this.ProductChoceVisible = false;
        this.$set(this.s_top, this.ProductChoceDesc, desc);
        this.$set(this.s_top, this.ProductChoceValue, value);
      },
    },
  }
</script>
